﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using System.Windows;
using Presentation.Shell.Interfaces;


namespace VPL.Shell
{
    using Presentation.Module.StudyDefinition;
    using Presentation.Module.Security;
    using Microsoft.Practices.Unity.InterceptionExtension;
    using Domain.UserManagement.Entities;
    using Domain.Common;
    using Infrastructure.Data.Security;
    using Infrastructure.CrossCutting.Security;
    using Presentation.Module.Security.Views;
    using Presentation.Module.Security.Interfaces.Views;
    using Application.Interfaces;
    using Application.UserManagement;
    using Domain.UserManagement;
    using Presentation.Module.Security.Interfaces.Services;
    using Presentation.Module.Security.Service;

    public class Bootstrapper : UnityBootstrapper
    {
        protected override System.Windows.DependencyObject CreateShell()
        {
            var shell = this.Container.Resolve<ShellWindow>();
            return shell;
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            System.Windows.Application.Current.MainWindow = (ShellWindow)this.Shell;
            System.Windows.Application.Current.MainWindow.Show();
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            
            Container.RegisterType<ILogon, Logon>();
            Container.RegisterType<ILogonService, LogonService>();

            Container.RegisterType<IPresentationModule, UserModule>(typeof(UserModule).Name);
            Container.RegisterType<IPresentationModule, Presentation.Module.Setup.SetupModule>(typeof(Presentation.Module.Setup.SetupModule).Name);
            Container.RegisterType<IPresentationModule, StudyDefinitionModule>(typeof(StudyDefinitionModule).Name);           
            Container.RegisterType<IPresentationModule, Presentation.Module.Scheduling.ScheduleStudyModule>(typeof(Presentation.Module.Scheduling.ScheduleStudyModule).Name);

            //register repositories
            Container.RegisterType<IUserRepository, UserRepository>();
            Container.RegisterType<IRoleRepository, RoleRepository>();
            Container.RegisterType<IPermissionRepository, PermissionRepository>();

            //register user service
            Container.RegisterType<IUserService, UserService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IUserManagementService, UserManagementService>();

            var context = new Infrastructure.Common.Data.Context();
            Container.RegisterInstance<Infrastructure.Common.Data.IContext>(context);
            Container.RegisterInstance<Domain.Common.IUnitOfWork>(context);
        }
    }
}